//
//  YMChangeButton.m
//  YMUIbutton
//
//  Created by 刘家俊 on 2017/7/28.
//  Copyright © 2017年 Andrew. All rights reserved.
//

#import "YMChangeButton.h"

#define LabelFontRegular(t) [UIFont fontWithName:@"PingFangHK-Regular" size:(t)]

@implementation YMChangeButton

//xib
- (void)awakeFromNib
{
    [super awakeFromNib];
}

//纯代码
- (instancetype)initWithFrame:(CGRect)frame
{
    if ([super initWithFrame:frame]) {
        
    }
    return self;
}

- (void)layoutSubviews
{
    [super layoutSubviews];
    
    NSRange range = [self.titleLabel.text rangeOfString:self.titleLabel.text];
    
    //设置普通状态下的文字属性
    NSMutableAttributedString *attributedStr = [[NSMutableAttributedString alloc] initWithString:self.titleLabel.text];
    [attributedStr addAttribute:NSFontAttributeName value:LabelFontRegular(15) range:range];
    [attributedStr addAttribute:NSForegroundColorAttributeName value:[UIColor purpleColor] range:range];
    [self setAttributedTitle:attributedStr forState:UIControlStateNormal];
    
    //设置选中状态下的文字属性
    NSMutableAttributedString *attributedStrS = [[NSMutableAttributedString alloc] initWithString:self.titleLabel.text];
    [attributedStrS addAttribute:NSFontAttributeName value:LabelFontRegular(20) range:range];
    [attributedStrS addAttribute:NSForegroundColorAttributeName value:[UIColor redColor] range:range];
    [self setAttributedTitle:attributedStrS forState:UIControlStateSelected];
    
}

@end
